package org.example.demo_xiaowuz.model;

import lombok.Data;
import org.example.demo_xiaowuz.enums.ResultCodeEnum;

@Data
public class Result<T> {
    private ResultCodeEnum code;
    private String msg;
    private T data;

    public static <T> Result<T> noLogin() {
        Result result=new Result<>();
        result.setCode(ResultCodeEnum.NOLOGIN);
        result.setMsg("用户未登录");
        return result;
    }

    public static <T> Result<T> success(T data) {
        Result result=new Result<>();
        result.setMsg("success");
        result.setCode(ResultCodeEnum.SUCCESS);
        result.setData(data);
        return result;
    }

    public static <T> Result<T> fail(String error) {
        Result result=new Result<>();
        result.setMsg(error);
        result.setCode(ResultCodeEnum.FAIL);
        return result;
    }
}
